import { reactive } from 'vue'

// 页面配置类型
export interface PageConfig {
    showNavBar: boolean;
    showTabBar: boolean;
    showSwitchNavBar: boolean;
    title?: string;
    backgroundColor?: string;
    customClass?: string;
    [key: string]: any; // 允许其他自定义配置
}

// 默认配置
const defaultConfig: PageConfig = {
    showNavBar: true,
    showTabBar: true,
    showSwitchNavBar: false,
    backgroundColor: '',
    customClass: ''
}

// 页面配置存储
const pageConfigs = reactive<Record<string, PageConfig>>({
    // 初始化默认页面配置
    '/home': {
        ...defaultConfig,
        title: 'home',
        showSwitchNavBar: true,
        showNavBar: false,
        showUserInfo: true,
        customClass: 'home-page',
    },
    '/fund-center': {
        ...defaultConfig,
        title: 'fundCenter',
        customClass: 'fund-center-page',
    },
    '/safe-box': {
        ...defaultConfig,
        title: 'safeBox',
        customClass: 'safe-box-page',
    },
    '/card-center': {
        ...defaultConfig,
        title: 'cardCenter',
        customClass: 'card-center-page',
    },
    '/mine': {
        ...defaultConfig,
        title: 'mine',
        showSwitchNavBar: true,
        showNavBar: false,
        showUserInfo: false,
        customClass: 'mine-page',
    },
    '/card-category': {
        showNavBar: true,
        title: 'cardCategory',
        customClass: 'card-category-page',
    },
    '/login': {
        ...defaultConfig,
        title: 'login',
        showNavBar: false,
    },
})

/**
 * 获取页面配置
 * @param path 路由路径
 * @returns 页面配置
 */
export function getPageConfig(path: string): PageConfig {
    return pageConfigs[path] || { ...defaultConfig }
}

/**
 * 设置页面配置
 * @param path 路由路径
 * @param config 页面配置
 */
export function setPageConfig(path: string, config: Partial<PageConfig>): void {
    if (!pageConfigs[path]) {
        pageConfigs[path] = { ...defaultConfig }
    }

    pageConfigs[path] = {
        ...pageConfigs[path],
        ...config
    }
}

/**
 * 重置页面配置
 * @param path 路由路径
 */
export function resetPageConfig(path: string): void {
    if (pageConfigs[path]) {
        pageConfigs[path] = { ...defaultConfig }
    }
}

export default {
    getPageConfig,
    setPageConfig,
    resetPageConfig
}